package com.wiiss.common.utils;

import lombok.extern.slf4j.Slf4j;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

@Slf4j
public class XMLUtils {

    /**
     * 根据属性name获取value
     * e.g. :
     * <property name="log.path" value="/root/mcs_java/logs" />，根据log.path 获取value
     */
    public static String getValueByName(Document doc, String name) {
        Element root = doc.getRootElement();
        List<Element> properties = root.elements("property");
        for (Element property : properties) {
            String tempName = property.attributeValue("name");
            if (name.equals(tempName)) {
                return property.attributeValue("value");
            }
        }
        return null;
    }

}
